if (!jsx3.lang.Class.forName("tibco.admin.enterpriseAssets.servers.plugins.AddPlugin")) {
    tibco.admin.Main.loadResource("tibco/admin/enterpriseAssets/servers/plugins/jss/jss.xml", "tibco.admin", "jss22C", "ljss", false);
    tibco.admin.Main.loadResource("tibco/admin/enterpriseAssets/servers/plugins/jss/xslt.xml", "tibco.admin", "xslt22C", "jss", false);

    /**
    **/
    jsx3.lang.Class.defineClass(
            "tibco.admin.enterpriseAssets.servers.plugins.AddPlugin",
            jsx3.lang.Object,
            null,
            function(upload) {
                upload.form = null;
                upload.block = null;
                upload.archivePath = "";
                upload.isIE = true;

                upload.initializeBrowser = function(block) {
//                    tibco.admin.util.DebugUtils.printTree(block);
                    upload.block = block;
                    if (document.getElementById && !document.all) {
                        // user is using NS6+ or Firefox
                        upload.isIE = false
                        // set blocks
                        upload.block.getDescendantOfName("blkUploadMoz900G").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                        upload.block.getDescendantOfName("blkUpload900G").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                        setTimeout(function() {
                            upload.initIFrame()
                        }, 100)

                    } else {
                        upload.enableUpload(false);
                        upload.block.getDescendantOfName("blkUploadMoz900G").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                        upload.block.getDescendantOfName("blkUpload900G").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                    }

                }

                /**
                 * If FF then create an iframe with a form element
                 */
                upload.initIFrame = function() {
                    upload.enableUpload(false)
                    var strAction = "/" + tibco.admin.util.ServiceHelper.getAdminWebapp() + "/" + "pluginupload/abc"
                    var theForm = '<form id="formMoz900G"  enctype="multipart/form-data"  method="post" action="' + strAction + '" ><input id="fileMoz2354AX" type="file" name="upfile" style="position:absolute;top:0;left:0" onchange="window.top.tibco.admin.enterpriseAssets.servers.plugins.AddPlugin.enableUpload(true)" ></input></form>';
                    var docHTML = '<html><head></head><body>' + theForm + '</body></html>';
                    upload._span = document.getElementById("spanMoz900G");
                    upload._iframe = document.getElementById("iFrameMoz900G");
                    upload._iframe.contentDocument.open();
                    upload._iframe.contentDocument.write(docHTML);
                    setTimeout(function() {
                        upload.form = upload._iframe.contentDocument.getElementById("formMoz900G")
                        upload._iframe.contentDocument.close();
                    }, 100)

                };

                upload.enableUpload = function(bool) {
                    upload.block.getDescendantOfName("btnUpload900G").setEnabled(bool?jsx3.gui.Form.STATEENABLED:jsx3.gui.Form.STATEDISABLED, true);
                }

                /*
                * Browsing for a file.
                */
                upload.doBrowse = function() {
                    jsx3.require('jsx3.net.Form');
                    if (upload.isIE) {
                        // Get the URL to post to
                        var strTestURL = "/" + tibco.admin.util.ServiceHelper.getAdminWebapp() + "/" + "pluginupload/abc";
                        tibco.admin.util.Log.RESOURCES.trace("About to browse for the plugin file.");
                        if (upload.form)
                            upload.doReset();
                        //get handle to the on-screen textbox that will show the user the name/path of the file they chose to upload
                        var objText = upload.block.getDescendantOfName("txtPluginArchive900G");
                        //check if the form has been created (it gets created when the file upload button is clicked)
                        if (!upload.form) {
                            // upload.form = new jsx3.net.Form(jsx3.net.Form.METHOD_POST, strTestURL, true);
                            upload.form = jsx3.net.Form.newFromFragment('<form id="pluginuploadform" enctype="multipart/form-data"  method="post" action="' + strTestURL + '"></form>');
                            //upload.form.setMultipart(true)
                            tibco.admin.util.Log.RESOURCES.trace("created form")
                            //add a file upload field. Give it an ID for later use (just use the name of the jsx textbox for now)
                            upload.form.addFileUploadField(objText.getName());

                            upload.form.subscribe(jsx3.net.Form.EVENT_FILE_SELECTED, function(objEvent) {
                                objText.setValue(objEvent.value);
                                upload.enableUpload(true);
                            });
                        }
                        upload.form.promptForFile(objText.getName());
                    }
                }

                /**
                 * submit to save the archive file (IE specific)
                 */
                upload.doSubmit = function(button) {
                    if (upload.isIE) {
                        if (!upload.form) {
                            tibco.admin.util.Log.RESOURCES.trace("form is null.");
                            upload.showError(tibco.admin.Main.getServer().getDynamicProperty("@@Null900G"), true);
                            upload.doReset();
                            return;
                        }

                        var pathField = upload.block.getDescendantOfName('txtPluginArchive900G');
                        upload.archivePath = pathField.getValue();
                        upload.block.getDescendantOfName('blkMessage900G').setText(tibco.admin.Main.getServer().getDynamicProperty("@@UploadInProgress900G"), true);
                        upload.form.subscribe(jsx3.HttpForm.EVENT_ON_RESPONSE, function(objEvent) {
                            upload.doProfile((new jsx3.xml.Document()).loadXML(upload.form.getResponseXML()));
                            upload.doReset();
                        });
                        upload.form.subscribe(jsx3.HttpForm.EVENT_ON_TIMEOUT, function(objEvent) {
                            tibco.admin.util.Log.RESOURCES.trace("Timeout reached")
                            upload.showError(tibco.admin.Main.getServer().getDynamicProperty("@@Timeout900G"), true);
                            upload.doReset();
                        });
                        upload.form.subscribe(jsx3.HttpForm.EVENT_ON_ERROR, function(objEvent) {
                        tibco.admin.util.Log.RESOURCES.trace("Error loading service asembly")
                            upload.showError(tibco.admin.Main.getServer().getDynamicProperty("@@UploadError900G"), true);
                            upload.doReset();
                        });
                        upload.form.setMultipart(true);
                        upload.form.send(500, 60000);
                    }
                    else {
                        upload.doSubmitMZ(button);
                    }
                }

                /**
                 * submit to save the archive file (FF specific)
                 */
                upload.doSubmitMZ = function(button) {
                    if (!upload.form) {
                        tibco.admin.util.Log.RESOURCES.trace("form is null.");
                        upload.showError(tibco.admin.Main.getServer().getDynamicProperty("@@Null900G"), true);
                        upload.form = null
                        return;
                    }
                    upload.block.getDescendantOfName('blkMessage900G').setText(tibco.admin.Main.getServer().getDynamicProperty("@@UploadInProgress900G"), true);
                    upload.form.encoding = 'multipart/form-data'
                    upload.send();
                }


                upload.send = function(intPollInterval, intTimeout) {
                    if (intPollInterval == null) intPollInterval = 10;
                    if (intTimeout == null) intTimeout = 30000;

                    upload._iframe.onload = function() {
                        upload.onIFrameLoad();
                    }

                    try {
                        upload.form.submit();
                    } catch (e) {
                        tibco.admin.util.Log.RESOURCES.trace("Error loading service assembly")
                        upload.showError(tibco.admin.Main.getServer().getDynamicProperty("@@UploadError900G"), true);
                        upload.doReset();
                        upload.initIFrame()
                        return;
                    }

                    upload._intervalId = window.setTimeout(function() {
                        upload.onIFrameTimeout();
                    }, intPollInterval * intTimeout);
                };

                /* @jsxobf-clobber */
                upload.onIFrameLoad = function() {
                    upload._iframe.onload = null;
                    if (upload._intervalId) {
                        window.clearTimeout(upload._intervalId);
                        upload._intervalId = null;
                    }

                    try {
                        var a = " " + this._iframe.contentDocument.childNodes[0].innerHTML;
                    } catch (e) {
                        jsx3.log("Error loading service asembly")
                        upload.showError(tibco.admin.Main.getServer().getDynamicProperty("@@UploadError900G"), true);
                        upload.doReset();
                        upload.initIFrame();
                        return;
                    }
                    upload.doProfile(upload.getResponseXML());
                    upload.doReset()
                    upload.initIFrame();

                };


                /* @jsxobf-clobber */
                upload.onIFrameTimeout = function() {
                    tibco.admin.util.Log.RESOURCES.trace("Timeout reached")
                    upload.showError(tibco.admin.Main.getServer().getDynamicProperty("@@Timeout900G"), true);
                    upload.doReset()
                    upload.initIFrame()

                };


                upload.getResponseXML = function() {
                    upload._iframe = document.getElementById("iFrameMoz900G");
                    var dcmt = upload._iframe.contentDocument;
                    if (dcmt instanceof XMLDocument) {
                        var x = (new XMLSerializer()).serializeToString(dcmt);
                        return new jsx3.xml.Document().loadXML(x);
                    }
                    else if (dcmt instanceof HTMLDocument) {
                        var x = dcmt.childNodes[0].innerHTML;
                        return new jsx3.xml.Document().loadXML(x);
                    } else {
                        tibco.admin.util.Log.RESOURCES.warn("Unsupported document type: " + dcmt);
                        return new jsx3.xml.Document().loadXML("<html/>");
                    }
                };


                upload.setField = function(name, value) {
                    var newInput = document.createElement('input');
                    newInput.setAttribute("type", "hidden");
                    newInput.setAttribute("name", name);
                    newInput.setAttribute("value", value);
                    upload.form.appendChild(newInput);
                }


                upload.validateAddServiceAssembly = function(nameField, fileField) {

                }

                upload.actionOnValidation = function(objText, passed, message) {
                    try {
                        if (!passed) {
                            objText.setBackgroundColor("yellow", true);
                            upload.showError(message)
                        }
                        else {
                            // Set the trimed value for node
                            //objText.setValue(strValue, true)
                            objText.setBackgroundColor("#FFFFFF", true);
                            upload.showError(message)
                        }
                    }
                    catch(e) {

                    }
                };

                /**
                 *
                 */
                upload.doProfile = function(objXML) {
                    try {
                        var successOrFailure = objXML.getRootNode().selectSingleNode("//status").getValue();
                        if (successOrFailure != "SUCCESS") {
                            var errorNodes = objXML.selectNodes("//error");
                            if (errorNodes.getLength() > 0) {
                                upload.doReset();
                                upload.showError(tibco.admin.Main.getServer().getDynamicProperty("@@CouldNotBeUpdated900G") + ":" + errorNodes.getItem(0).getValue());
                            }
                        }
                        else {
                            tibco.admin.Main.getServer().getJSXByName("Root900G").callgetInstalledPlugins();
                            upload.block.getDescendantOfName('blkMessage900G').setText("", true);
                            upload.block.doClose();
                            tibco.admin.Main.alert(tibco.admin.Main.getServer().getDynamicProperty("@@txtUploadSuccessTitle900G"),
                                                   tibco.admin.Main.getServer().getDynamicProperty("@@txtUploadSuccessDetail900G"));
                        }
                        tibco.admin.util.Log.RESOURCES.trace("Response from file upload [" + successOrFailure + "].")
                        if (successOrFailure == "") {
                            try {
                                tibco.admin.Main.getServer().getJSXByName("Root900G").callgetInstalledPlugins();
                            }
                            catch(e) {
                                upload.doReset();
                                upload.showError(tibco.admin.Main.getServer().getDynamicProperty("@@CouldNotBeRetrieved900G"));
                            }
                        }
                        else {
                            upload.doReset();
                        }
                    }
                    catch(e) {
                        upload.showError(tibco.admin.Main.getServer().getDynamicProperty("@@CouldNotBeUpdated900G"));
                        upload.doReset();
                        if (!upload.isIE) {
                            upload.initIFrame()
                        }

                    }
                }

                upload.doReset = function() {
                    if (upload.isIE && upload.form)
                        upload.form.destroy();
                    upload.form = null;
                    upload.block.getDescendantOfName("txtPluginArchive900G").setValue("");
                    upload.block.getDescendantOfName("blkUploadMoz900G").repaint();
                    upload.enableUpload(false);
                }

                upload.showError = function(msg) {
                    upload.block.getDescendantOfName('blkMessage900G').setText(msg, true);
                }

            }
            )

}
